import requests
import app

# 登录成功
resp = requests.post(url=app.BASE_URL + '/api/sys/login',
                     headers=app.HEADERS,
                     json={'mobile': '13800000002', 'password': '123456'})
print(resp.json())

# 获取令牌
token = 'Bearer ' + resp.json().get('data')
print(token)

# 添加员工
resp_add = requests.post(url=app.BASE_URL + '/api/sys/user',
                         headers={'Content-Type': 'application/json',
                                  'Authorization': token},
                         json={"username": "小猪佩奇过大年",
                               "mobile": "13987650035",
                               "timeOfEntry": "2021-02-02",
                               "formOfEmployment": 1,
                               "workNumber": "1234",
                               "departmentName": "测试部",
                               "departmentId": "1063678149528784896",
                               "correctionTime": "2021-02-22T16:00:00.000Z"})
print('添加员工结果为：', resp_add.json())

# 获取员工id
emp_id = resp_add.json().get('data').get('id')
print('员工id为：', emp_id)

# 查询员工
resp_query = requests.get(url=app.BASE_URL + '/api/sys/user' + '/' + emp_id,
                          headers={'Content-Type': 'application/json',
                                   'Authorization': token})
print('按id查询员工结果为：', resp_query.json())

# 修改员工
resp_modify = requests.put(url=app.BASE_URL + '/api/sys/user' + '/' + emp_id,
                           headers={'Content-Type': 'application/json',
                                    'Authorization': token},
                           json={'username': '爱因斯坦'})
print('按id修改员工结果为：', resp_modify.json())

# 再次查询
resp_query = requests.get(url=app.BASE_URL + '/api/sys/user' + '/' + emp_id,
                          headers={'Content-Type': 'application/json',
                                   'Authorization': token})
print('按id，再次查询员工结果为：', resp_query.json())

# 删除员工
resp_del = requests.delete(url=app.BASE_URL + '/api/sys/user' + '/' + emp_id,
                           headers={'Content-Type': 'application/json',
                                    'Authorization': token})
print('按id删除员工结果为：', resp_del.json())

# 查询员工列表
resp_querys = requests.get(url=app.BASE_URL + '/api/sys/user?page=1&size=10',
                           headers={'Content-Type': 'application/json',
                                    'Authorization': token})
print('查询员工列表：', resp_querys.json())
